(function () {
    var form = layui.form
    form.verify({
        pass:[
            /^[\S]{6,12}$/
            ,'密码必须6到12位，且不能出现空格'
        ]
        , repass: function (value) {
            let mima = document.getElementById('mima')
            if (value !== mima.value)
                return "两次密码不同"
        }
    })

    var ma = document.getElementById('yanzhengm');
    var huan = document.getElementById('huan');
    var tuxingma = document.getElementById('tuxingma');
    var errma = document.getElementById('errma');
    
    tuxingma.onblur = function () {
        if (this.value !== ma.innerHTML) {
            errma.style.display = 'block'
            return
            
        }
        errma.style.display = 'none'

    }
    huan.onclick = function () {
        var arr ='';
        for (let i = 0; i < 4; i++) {
            arr += random(0, 9)
        }
        ma.innerText = arr;
    }
    huan.onclick()
    function random(a, b) {
        return Math.ceil(Math.random()*(b-a+1)+a-1);   
    }
    
    var userphone = document.getElementById('userphone')
    var errtu = document.getElementsByClassName('errtu');
    userphone.onblur = function () {
        let regexp = new RegExp(/^[1][\d]{10}/)
        errtu[0].style.display = 'block'
        if (regexp.test(this.value)) {
            errtu[0].style.backgroundPosition = '0 -200px'
        }
        else {
            
            errtu[0].style.backgroundPosition = '-40px -200px'
        }
    }
    var mima = document.getElementById('mima')
    mima.onblur = function () {
        let regexp = new RegExp(/[\S]{6,12}/)
        errtu[1].style.display = 'block'
        if (regexp.test(this.value)) {
            errtu[1].style.backgroundPosition = '0 -200px'
        }
        else {
            
            errtu[1].style.backgroundPosition = '-40px -200px'
        }
    }
    var remima = document.getElementById('remima')
    remima.onblur = function () {
        errtu[2].style.display = 'block'
        if (this.value === mima.value) {
            errtu[2].style.backgroundPosition = '0 -200px'
        }
        else {
            
            errtu[2].style.backgroundPosition = '-40px -200px'
        }
    }

    var huoqu = document.getElementById('huoqu')
    var flag = true;
    huoqu.onclick = function () {
        if (flag) {
            flag = false
            let i = 60
            huoqu.innerHTML = i;
            var timer = setInterval(function () {
                i--;
                huoqu.innerHTML = i;
                if (i === 0) {
                    clearInterval(timer);
                    huoqu.innerHTML = "获取验证码"
                    flag = true;
                    return
                }
                    
            },1000)
        }
    }

    var layui_form = document.getElementsByClassName('layui-form')[0];



    var guding = document.getElementById('guding')
    guding.onmouseover = function () {
        guding.style.backgroundPosition = '-56px -46px'
    }
    guding.onmouseout = function () {
        guding.style.backgroundPosition = '0 -46px'
    }


    layui_form.onsubmit = function () {
        event.preventDefault();
    }
})()